﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GpCommon.Models
{
    /// <summary>
    /// 日线数据类
    /// </summary>
    public class GpDayEntity
    {
        public string Code { get; set; }
        public string Name { get; set; }
        /// <summary>
        /// 日期
        /// </summary>
        public DateTime Time { get; set; }
        /// <summary>
        /// 开盘价
        /// </summary>
        public float PrePrice { get; set; }
        /// <summary>
        /// 收盘价
        /// </summary>
        public float ClsPrice { get; set; }
        /// <summary>
        /// 最高价
        /// </summary>
        public float HighPrice { get; set; }
        /// <summary>
        /// 最低价
        /// </summary>
        public float LowPrice { get; set; }
        /// <summary>
        /// 涨跌幅
        /// </summary>
        public float MarkUp { get; set; }
        /// <summary>
        /// 涨跌额
        /// </summary>
        public float MarkUpPrice { get; set; }
        /// <summary>
        /// 成交量
        /// </summary>
        public float Volume { get; set; }
        /// <summary>
        /// 成交额
        /// </summary>
        public float TurnVolume { get; set; }
        /// <summary>
        /// 振幅
        /// </summary>
        public float Amplitude { get; set; }
        /// <summary>
        /// 换手
        /// </summary>
        public float ChangeHands { get; set; }

        //  计算所得
        /// <summary>
        /// 5日均线
        /// </summary>
        public float Day5Price { get; set; } = -1f;
        /// <summary>
        /// 10日均线
        /// </summary>
        public float Day10Price { get; set; } = -1f;
        /// <summary>
        /// 20日均线
        /// </summary>
        public float Day20Price { get; set; } = -1f;
        /// <summary>
        /// 30日均线
        /// </summary>
        public float Day30Price { get; set; } = -1f;
        /// <summary>
        /// 60日均线
        /// </summary>
        public float Day60Price { get; set; } = -1f;

        #region macd指标
        public float EMA12 { get; set; }
        public float EMA26 { get; set; }
        public float DIF { get; set; }
        public float DEA { get; set; }
        public float MACD { get; set; }
        #endregion

        #region kdj指标
        public float RSV { get; set; }
        public float K { get; set; }
        public float D { get; set; }
        public float J { get; set; }

        #endregion

        public static GpDayEntity Create(string entStr)
        {
            if (string.IsNullOrEmpty(entStr)) { return null; }
            var strs = entStr.Split(',');
            if (strs.Length != 13) return null;
            GpDayEntity ent = new GpDayEntity();
            ent.Code = strs[0];
            ent.Name = strs[1];
            ent.Time = DateTime.Parse(strs[2]);
            ent.PrePrice = float.Parse(strs[3]);
            ent.ClsPrice = float.Parse(strs[4]);
            ent.HighPrice = float.Parse(strs[5]);
            ent.LowPrice = float.Parse(strs[6]);
            ent.MarkUp = float.Parse(strs[7]);
            ent.MarkUpPrice = float.Parse(strs[8]);
            ent.Volume = float.Parse(strs[9]);
            ent.TurnVolume = float.Parse(strs[10]);
            ent.Amplitude = float.Parse(strs[11]);
            ent.ChangeHands = float.Parse(strs[12]);
            return ent;
        }
        public override string ToString()
        {
            return string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}",
                Code, Name, Time.ToShortDateString(), PrePrice, ClsPrice, HighPrice, LowPrice, MarkUp, MarkUpPrice, Volume, TurnVolume, Amplitude, ChangeHands);
        }

        public static GpDayEntity CreateFromGpCurEntity(GpCurEntity gpCur)
        {
            GpDayEntity ent = new GpDayEntity();
            ent.Code = gpCur.Code;
            ent.Name = gpCur.Name;
            ent.Time = DateTime.Today;
            ent.PrePrice = gpCur.PrePrice;
            ent.ClsPrice = gpCur.CurPrice;
            ent.HighPrice = gpCur.HighPrice;
            ent.LowPrice = gpCur.LowPrice;
            ent.MarkUp = gpCur.CurMarkUp;
            ent.MarkUpPrice = gpCur.CurMarkUpValue;
            ent.Volume = gpCur.Volume;
            ent.TurnVolume = gpCur.TurnVolume;
            ent.Amplitude = gpCur.Amplitude;
            ent.ChangeHands = gpCur.ChangeHands;
            return ent;
        }    
    }

}
